package com.csu.cphone.controller.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.csu.common.vo.ResultVo;
import com.csu.cphone.pojo.MaintainSelectAnswerPojo;
import com.csu.cphone.service.MaintainSelectAnswerService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * @项目名称：cphone
 * @类名称：MaintainSelectAnswerManager
 * @类描述：
 * @创建人：Tangc
 * @创建时间：2017年12月3日 下午10:50:00
 * @company:
 */
@Controller
@RequestMapping("admin/maintain/answer")
@Api(value = "admin", description = "管理后台")
public class MaintainSelectAnswerManager
{
    @Autowired
    private MaintainSelectAnswerService selectAnswerService;

    @ResponseBody
    @ApiOperation(value = "添加", notes = "添加数据")
    @RequestMapping(value = "/add", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<MaintainSelectAnswerPojo> add(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "维修手机id") @RequestParam(value = "maintainPhoneId", required = true) Integer maintainPhoneId,
            @ApiParam(value = "订单sn") @RequestParam(value = "maintainOrderSn", required = true) String maintainOrderSn,
            @ApiParam(value = "维修问题id") @RequestParam(value = "maintainProblemId", required = true) Integer maintainProblemId,
            @ApiParam(value = "问题选项id") @RequestParam(value = "maintainProblemSelectId", required = true) Integer maintainProblemSelectId,
            @ApiParam(value = "扣款") @RequestParam(value = "cost", required = true) Double cost)
    {

        ResultVo<MaintainSelectAnswerPojo> resultVo = new ResultVo<MaintainSelectAnswerPojo>();
        // 添加
        MaintainSelectAnswerPojo result = selectAnswerService.add(maintainPhoneId, maintainOrderSn, maintainProblemId,
                maintainProblemSelectId, cost);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "更新", notes = "更新数据，返回1成功")
    @RequestMapping(value = "/update", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<Integer> update(HttpServletRequest request, HttpServletResponse response,
            @RequestBody MaintainSelectAnswerPojo selectPojo)
    {

        ResultVo<Integer> resultVo = new ResultVo<Integer>();
        // 添加
        Integer result = selectAnswerService.update(selectPojo);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "查询", notes = "单个")
    @RequestMapping(value = "/queryById", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<MaintainSelectAnswerPojo> queryById(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "维修问题id") @RequestParam(value = "maintainProblemId", required = true) Integer maintainProblemId)
    {

        ResultVo<MaintainSelectAnswerPojo> resultVo = new ResultVo<MaintainSelectAnswerPojo>();
        // 添加
        MaintainSelectAnswerPojo result = selectAnswerService.queryById(maintainProblemId);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "查询总数", notes = "总数")
    @RequestMapping(value = "/count", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<Integer> count(HttpServletRequest request, HttpServletResponse response,
            @ApiParam(value = "订单sn") @RequestParam(value = "maintainOrderSn", required = false) String maintainOrderSn)
    {
        ResultVo<Integer> resultVo = new ResultVo<Integer>();
        // 添加
        Integer result = selectAnswerService.count(maintainOrderSn);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "查询列表", notes = "分页")
    @RequestMapping(value = "/queryList", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<List<MaintainSelectAnswerPojo>> queryList(HttpServletRequest request, HttpServletResponse response,
            @ApiParam(value = "页面大小") @RequestParam(value = "pageSize", required = true) Integer pageSize,
            @ApiParam(value = "开始位置") @RequestParam(value = "startIndex", required = true) Integer startIndex,
            @ApiParam(value = "排序") @RequestParam(value = "order", required = false) String order,
            @ApiParam(value = "订单sn") @RequestParam(value = "maintainOrderSn", required = false) String maintainOrderSn)
    {

        ResultVo<List<MaintainSelectAnswerPojo>> resultVo = new ResultVo<List<MaintainSelectAnswerPojo>>();
        // 添加
        if (!"DESC".equalsIgnoreCase(order))
        {
            order = "ASC";
        }
        List<MaintainSelectAnswerPojo> result = selectAnswerService.queryList(pageSize, startIndex, order,maintainOrderSn);
        resultVo.setData(result);

        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "删除", notes = "删除数据")
    @RequestMapping(value = "/delById", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<Integer> deleteById(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "维修问题id") @RequestParam(value = "maintainProblemId", required = true) Integer maintainProblemId)
    {

        ResultVo<Integer> resultVo = new ResultVo<Integer>();
        // 添加
        Integer result = selectAnswerService.deleteById(maintainProblemId);
        resultVo.setData(result);

        return resultVo;
    }
}
